/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Connections;

import Object.User;
import java.sql.CallableStatement;
import java.sql.Connection;

/**
 *
 * @author nguyen
 */
public class UserDB {
    private String url;
    private String user;
    private String password;

    public UserDB(String url, String user, String password) {
        this.url = url;
        this.user = user;
        this.password = password;
    }
    
    public  boolean insertUserAccount(User u){
        try {
            Connection conn = ConnectionUtil.getConnection(url, user, password);
           CallableStatement cstmt = conn.prepareCall("{call createAccount(?, ?, ?, ?, ?, ?, ?)}");
                cstmt.setString(1, u.getUsername());
                cstmt.setString(2, u.getPassword());
                cstmt.setString(3, u.getFullname());
                cstmt.setString(4, u.getDateofbirth());
                cstmt.setString(5, u.getEmail());
                cstmt.setString(6, u.getPhonenumber());
                cstmt.setString(7, u.getImage());
                int rows = cstmt.executeUpdate();
                conn.close();
                return rows > 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
